<?php
namespace app\common\model;
use app\common\cache\CacheData;

class Level extends Base
{

	public function cacheData(){
		$data = $this -> select();
		if($data){
			foreach($data as &$value):
				$value = $value->toArray();
			endforeach;
		}
		return $data;
	}

	/**
     * 等级缓存
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public static function levelData($id=null){
        $CACHE = CacheData::getInstance('Level');
        $cacheData = $CACHE -> readCache();
        $levelsData = [];
        foreach($cacheData as $cache):
            $levelsData[$cache['id']] = $cache;
        endforeach;
        if(!is_null($id)){
            if(isset($levelsData[$id])):
                return $levelsData[$id];
            else:
                return false;
            endif;
        }else{
            return $levelsData;
        }
    }

    public function deleteOneData($id){
    	//TODO
    	return false;
        $count = $this->where(['id'=>$id])->value('member_count');
        if($count>0){
            $this->error = '该等级下存在会员，无法删除该等级';
            return false;
        }
        if($model->where(['id'=>$id])->delete()){
            return true;
        }else{
            $this->error = '删除失败';
            return false;
        }
    }


}
